#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : PythonProject4
@File : mysql_val.py
@Author : 你的名字  张三 李四
@Time : 2025/7/6 14:43  
@脚本说明 : 

"""

import threading
import pymysql


def scan_mysql(host, port, user, password):
    try:
        pymysql.connect(
            host=host,
            port=port,
            user=user,
            password=password,
            database="information_schema",
            connect_timeout=3
        )
        print(f"[+] MySQL {host}:{port} 存在弱口令, {user}:{password}")
        with open(file="./mysql_result.txt", mode="a+", encoding="utf-8") as f:
            f.write(f"[+] MySQL {host}:{port} 存在弱口令, {user}:{password}\n")
    except:
        pass


def val_mysql(host, port, user, file):
    try:
        thread_list = []
        with open(f"{file}", mode='r', encoding="utf-8") as p:
            for passwd in p:
                t = threading.Thread(target=scan_mysql, args=(host, port, user.strip(), passwd.strip()))
                t.start()
                thread_list.append(t)
        for t in thread_list:
            t.join()
    except:
        print("[-] 读取弱口令文件出错")
